package editor;

import editor.widgets.MessagePopup;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
 * This class provides methods for displaying error messages to the user.
 *
 * @author Neil Dickson
 */
public class ErrorHandler {
	public static void showNotImplementedMessage(String message) {
		System.err.println(message);
		new MessagePopup(PwnIDE.editor,null,message).setVisible(true);
	}
	public static void showMessage(String message) {
		System.err.println(message);
		new MessagePopup(PwnIDE.editor,null,message).setVisible(true);
	}
	public static void showException(Throwable e) {
		showException(e,"Oh noes!  An error has occurred!");
	}

	public static void showException(Throwable e, String message) {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		PrintStream stream = new PrintStream(output);
		e.printStackTrace(stream);
		stream.flush();
		String trace = output.toString();
		e.printStackTrace();
		new MessagePopup(PwnIDE.editor,null,message+"\n\nIt probably doesn't mean anything to you, but here's the stack trace:\n\n"+trace).setVisible(true);
	}
}
